﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace Admin
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            lblErro.Text = String.Empty;
            Donini.Crypt.Crypt c = new Donini.Crypt.Crypt(Donini.Crypt.CryptProvider.Rijndael);
            c.Key = "chocolate";
            string _senhaCripto = c.Encrypt(txtSenha.Text);
            if (new LojaAdminDataContext().GetTable<Usuario>()
                .Where(user => user.UsuLog == txtUsuario.Text.Trim() && user.UsuSen == _senhaCripto.Trim())
                .SingleOrDefault() != null)
            {
                FormsAuthentication.RedirectFromLoginPage(txtUsuario.Text, true);
                Session["user"] = txtUsuario.Text;
            }
            else
            {
                lblErro.Text = "Erro ao acessar o sistema, verifique usuário ou senha.";
            }
        }
    }
}